from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-10 14:02:10.907179
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 10, Jul, 2022
Time: 14:02:17
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.7528
Nobs: 713.000 HQIC: -50.1068
Log likelihood: 8927.16 FPE: 1.38727e-22
AIC: -50.3295 Det(Omega_mle): 1.22384e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298470 0.057321 5.207 0.000
L1.Burgenland 0.104514 0.037627 2.778 0.005
L1.Kärnten -0.109454 0.019950 -5.486 0.000
L1.Niederösterreich 0.210068 0.078699 2.669 0.008
L1.Oberösterreich 0.105693 0.076983 1.373 0.170
L1.Salzburg 0.257067 0.040278 6.382 0.000
L1.Steiermark 0.044748 0.052457 0.853 0.394
L1.Tirol 0.109668 0.042592 2.575 0.010
L1.Vorarlberg -0.061054 0.036836 -1.657 0.097
L1.Wien 0.045675 0.067937 0.672 0.501
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.047753 0.119985 0.398 0.691
L1.Burgenland -0.034185 0.078762 -0.434 0.664
L1.Kärnten 0.041208 0.041760 0.987 0.324
L1.Niederösterreich -0.167542 0.164733 -1.017 0.309
L1.Oberösterreich 0.422715 0.161142 2.623 0.009
L1.Salzburg 0.288382 0.084311 3.420 0.001
L1.Steiermark 0.100566 0.109804 0.916 0.360
L1.Tirol 0.318655 0.089154 3.574 0.000
L1.Vorarlberg 0.027332 0.077106 0.354 0.723
L1.Wien -0.037548 0.142205 -0.264 0.792
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187946 0.029330 6.408 0.000
L1.Burgenland 0.089544 0.019253 4.651 0.000
L1.Kärnten -0.007948 0.010208 -0.779 0.436
L1.Niederösterreich 0.264597 0.040269 6.571 0.000
L1.Oberösterreich 0.137853 0.039391 3.500 0.000
L1.Salzburg 0.046162 0.020610 2.240 0.025
L1.Steiermark 0.020000 0.026842 0.745 0.456
L1.Tirol 0.091469 0.021794 4.197 0.000
L1.Vorarlberg 0.057226 0.018849 3.036 0.002
L1.Wien 0.114363 0.034762 3.290 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111838 0.029827 3.750 0.000
L1.Burgenland 0.045166 0.019579 2.307 0.021
L1.Kärnten -0.013778 0.010381 -1.327 0.184
L1.Niederösterreich 0.191045 0.040951 4.665 0.000
L1.Oberösterreich 0.303326 0.040058 7.572 0.000
L1.Salzburg 0.108362 0.020959 5.170 0.000
L1.Steiermark 0.104706 0.027296 3.836 0.000
L1.Tirol 0.104087 0.022163 4.697 0.000
L1.Vorarlberg 0.066603 0.019168 3.475 0.001
L1.Wien -0.021976 0.035351 -0.622 0.534
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134570 0.054393 2.474 0.013
L1.Burgenland -0.051968 0.035705 -1.455 0.146
L1.Kärnten -0.044354 0.018931 -2.343 0.019
L1.Niederösterreich 0.155966 0.074679 2.088 0.037
L1.Oberösterreich 0.139782 0.073051 1.913 0.056
L1.Salzburg 0.286880 0.038221 7.506 0.000
L1.Steiermark 0.047609 0.049778 0.956 0.339
L1.Tirol 0.167155 0.040416 4.136 0.000
L1.Vorarlberg 0.092035 0.034955 2.633 0.008
L1.Wien 0.074665 0.064466 1.158 0.247
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055225 0.043273 1.276 0.202
L1.Burgenland 0.037987 0.028405 1.337 0.181
L1.Kärnten 0.050945 0.015061 3.383 0.001
L1.Niederösterreich 0.217132 0.059411 3.655 0.000
L1.Oberösterreich 0.295244 0.058116 5.080 0.000
L1.Salzburg 0.048030 0.030407 1.580 0.114
L1.Steiermark 0.001420 0.039601 0.036 0.971
L1.Tirol 0.141364 0.032153 4.397 0.000
L1.Vorarlberg 0.072651 0.027808 2.613 0.009
L1.Wien 0.080917 0.051286 1.578 0.115
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174964 0.051742 3.381 0.001
L1.Burgenland -0.002873 0.033965 -0.085 0.933
L1.Kärnten -0.062978 0.018008 -3.497 0.000
L1.Niederösterreich -0.081436 0.071039 -1.146 0.252
L1.Oberösterreich 0.194374 0.069490 2.797 0.005
L1.Salzburg 0.056740 0.036358 1.561 0.119
L1.Steiermark 0.235734 0.047352 4.978 0.000
L1.Tirol 0.497593 0.038446 12.943 0.000
L1.Vorarlberg 0.043551 0.033251 1.310 0.190
L1.Wien -0.053133 0.061324 -0.866 0.386
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170733 0.059053 2.891 0.004
L1.Burgenland -0.010445 0.038764 -0.269 0.788
L1.Kärnten 0.063608 0.020553 3.095 0.002
L1.Niederösterreich 0.206531 0.081077 2.547 0.011
L1.Oberösterreich -0.074967 0.079309 -0.945 0.345
L1.Salzburg 0.213188 0.041495 5.138 0.000
L1.Steiermark 0.125543 0.054042 2.323 0.020
L1.Tirol 0.068819 0.043879 1.568 0.117
L1.Vorarlberg 0.118376 0.037949 3.119 0.002
L1.Wien 0.121083 0.069989 1.730 0.084
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.362630 0.034209 10.600 0.000
L1.Burgenland 0.006426 0.022456 0.286 0.775
L1.Kärnten -0.023478 0.011906 -1.972 0.049
L1.Niederösterreich 0.216312 0.046967 4.606 0.000
L1.Oberösterreich 0.202198 0.045943 4.401 0.000
L1.Salzburg 0.043319 0.024038 1.802 0.072
L1.Steiermark -0.014996 0.031306 -0.479 0.632
L1.Tirol 0.104915 0.025419 4.127 0.000
L1.Vorarlberg 0.069989 0.021984 3.184 0.001
L1.Wien 0.034808 0.040544 0.859 0.391
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037420 0.139077 0.194687 0.155952 0.115293 0.102768 0.057420 0.217315
Kärnten 0.037420 1.000000 -0.015713 0.134094 0.055950 0.094996 0.435650 -0.053597 0.093615
Niederösterreich 0.139077 -0.015713 1.000000 0.335512 0.141186 0.293759 0.092397 0.176032 0.312929
Oberösterreich 0.194687 0.134094 0.335512 1.000000 0.227245 0.325154 0.176492 0.164440 0.262173
Salzburg 0.155952 0.055950 0.141186 0.227245 1.000000 0.138110 0.116820 0.138372 0.129219
Steiermark 0.115293 0.094996 0.293759 0.325154 0.138110 1.000000 0.145268 0.131673 0.070698
Tirol 0.102768 0.435650 0.092397 0.176492 0.116820 0.145268 1.000000 0.110691 0.142436
Vorarlberg 0.057420 -0.053597 0.176032 0.164440 0.138372 0.131673 0.110691 1.000000 -0.001557
Wien 0.217315 0.093615 0.312929 0.262173 0.129219 0.070698 0.142436 -0.001557 1.000000